<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的遍历  列表</title>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //1. 准备数据
        let students = [
            {name: '张三', age:20, gender: '男'},
            {name: '孙红', age:20, gender: '女'},
            {name: '李四', age:21, gender: '男'},
            {name: '赵小花', age:21, gender: '女'},
            {name: '鸠摩智', age:30, gender: '男'},
        ];

        //类式组件
        class Student extends React.Component{
            render(){
                //结构赋值
                let {name, age, gender} = this.props;
                return <div>
                        <ul>
                            <li>姓名: {name}</li>
                            <li>年龄: {age}</li>
                            <li>性别: {gender}</li>
                        </ul>
                    </div>
            }
        }

        //声明类式组件
        class App extends React.Component{
            render(){
                return <div>
                    <h2>学生列表</h2>
                    <hr />
                    {
                        students.map((item, index) => {
                            return <Student key={index} {...item} />
                        })
                    }
                </div>
            }
        }
        
        ReactDOM.render(<App />, document.querySelector("#root"))

    </script>
</body>
</html>